package org.jdsm.gae.komarichyn;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

/**
 * Created with IntelliJ IDEA.
 * User: mikom
 * Date: 11/2/12
 * Time: 3:43 PM
 */
public class ApplicationSessionListener implements HttpSessionListener, ServletContextListener {
    @Override
    public void sessionCreated(HttpSessionEvent se) {
        HttpSession session = se.getSession();
        String path = session.getServletContext().getContextPath();
        session.setAttribute("cntxpth", path);
    }

    @Override
    public void sessionDestroyed(HttpSessionEvent se) {

    }

    @Override
    public void contextInitialized(ServletContextEvent sce) {
        ServletContext context = sce.getServletContext();
        String path = context.getContextPath();
        context.setAttribute("cntxpth", path);
        context.setAttribute("templateName", "homepage");

    }

    @Override
    public void contextDestroyed(ServletContextEvent sce) {

    }
}
